package com.xyzwps.server.paimon.it

import com.xyzwps.server.paimon.jackson.JSON
import org.springframework.http.codec.json.Jackson2JsonDecoder
import org.springframework.http.codec.json.Jackson2JsonEncoder
import org.springframework.test.web.reactive.server.WebTestClient
import java.util.concurrent.atomic.AtomicLong

object UiTestHelper {
    fun createWebTestClient(baseUrl: String): WebTestClient {
        return WebTestClient.bindToServer()
            .baseUrl(baseUrl)
            .build()
            .mutateWith { builder, httpHandlerBuilder, connector ->
                builder.codecs { configurer ->
                    configurer.defaultCodecs().apply {
                        jackson2JsonEncoder(Jackson2JsonEncoder(JSON.OM))
                        jackson2JsonDecoder(Jackson2JsonDecoder(JSON.OM))
                    }
                }
            }
    }

    private val PHONE_SEQ = AtomicLong(138_0000_0000L)

    fun genPhone(): String {
        return PHONE_SEQ.incrementAndGet().toString()
    }
}
